#include <iostream>
#include <string>
#include "contacts.pb.h"

int main() {
    std::string peo_str;
    // 定义联系人
    contacts::PersonInfo people;
    people.set_name("ming");
    people.set_age(20);
    // 序列化
    if(!people.SerializeToString(&peo_str)) {
        std::cerr << "序列化联系人失败！" << std::endl;
        return -1;
    }

    // 字符串存的是二进制序列
    std::cout << "序列化成功，结果为：" << peo_str << std::endl;

    // 反序列化
    contacts::PersonInfo retpeople;
    if(!retpeople.ParseFromString(peo_str)) {
        std::cerr << "反序列化联系人失败！" << std::endl;
        return -1;
    }
    std::cout << "反序列化成功！" << std::endl
        << "姓名：" << retpeople.name() << std::endl
        << "年龄：" << retpeople.age() << std::endl;


    return 0;
}